package com.thiny.android.app.tnote.ui;

import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.thiny.android.app.tnote.Constants;
import com.thiny.android.app.tnote.R;
import com.thiny.android.app.tnote.datebase.SQLiteHelper;
import com.thiny.android.app.tnote.model.Note;

public class SettingActivity extends BaseActivity implements OnClickListener {

	private EditText contentEditText;
	private TextView titleTextView;
	private Note mNote;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mNote = (Note) getIntent().getSerializableExtra(Constants.EXTRA_NOTE);
		setContentView(R.layout.setting_layout);
		findViewById(R.id.add).setOnClickListener(this);
		titleTextView = (TextView) findViewById(R.id.note_title);
		titleTextView.setText(DateFormat.format("yyyy年M月d日", mNote.getDate()));
		contentEditText = (EditText) findViewById(R.id.note_content_edit);
		String content = mNote.getContent();
		contentEditText.setText(content);
	}

	public void onClick(View v) {
		 
//		note.setId(Integer.parseInt(idEditText.getText().toString()));
		mNote.setContent(contentEditText.getText().toString());
		
//		note.setTitle("测试");
//		note.setContent("哈哈哈");
		mNote.setCreateTime(System.currentTimeMillis());
		SQLiteHelper.getInstance(this).insert(mNote);
		Toast.makeText(this, "保存成功", Toast.LENGTH_SHORT).show();
		finish();
	}

}
